home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DSIIC2.ARJ / L_WIN4.C < prev    next >
C/C++ Source or Header  |  1991-07-15  |  8KB  |  284 lines

  1. /* Copyright (c) James L. Pinson 1990,1991  */
  2.  
  3. /**********************   L_WIN4.C   ***************************/
  4.  
  5. #include "mydef.h"
  6. #include <dos.h>
  7.  
  8. #if defined QUICKC
  9.  
  10. #include "malloc.h"
  11. #include "memory.h"
  12.  
  13. #endif
  14.  
  15. #if defined TURBOC
  16.  
  17. #include "alloc.h"    /* Turbo C header file */
  18. #include "mem.h"
  19. #include "string.h"
  20. #include "stdlib.h"
  21.  
  22. #endif
  23.  
  24.  
  25. /*****************************************************************
  26.  
  27.  Usage: void win_up(int handle, int amount);
  28.  
  29.  int handle = window handle
  30.  int amount = the number of lines to move the window.
  31.  
  32.  Moves the window indicated up on the screen, the screen is
  33.  updated to show the movement.  If there is insufficient space
  34.  to move the requested amount, the window is moved as far as
  35.  possible.
  36.  
  37. *****************************************************************/
  38.  
  39. void win_up(int handle, int amount)
  40. {
  41. extern struct  screen_structure scr;
  42. extern struct window_structure w[];
  43.  int win_top;
  44.  
  45.  /* if the window selected is on top then save */
  46.  if(scr.active==handle)
  47.     win_save();
  48.  
  49.     /* calculate true top of window.
  50.        this depends on presence of frame */
  51.  
  52.     if(w[handle].frame==TRUE) win_top=w[handle].top-1;
  53.      else win_top=w[handle].top;
  54.  
  55.      if(win_top==1) return;  /*return if already on top*/
  56.  
  57.      /* adjust amount of movement if there is not space */
  58.      if(win_top-amount<=0)amount=win_top-1;
  59.  
  60.     /* change the window margin definitions to show the changes */
  61.     w[handle].top-= amount;
  62.     w[handle].bottom-= amount;
  63.  
  64.  win_redraw_all(); /* show the changes */
  65.  
  66.  if(scr.active==handle){     /* if the window is active */
  67.    free(w[handle].buffer) ;  /* free the memory */
  68.    w[handle].buffer=NULL ;
  69.    update_margins();         /* change the screen margins */
  70.                              /* to reflect the new active */
  71.                              /* window area */
  72.    display_cursor();     /* update cursor position */
  73.  }
  74. }
  75.  
  76.  
  77. /*****************************************************************
  78.  
  79.  Usage: void win_right(int handle, int amount);
  80.  
  81.  int handle = window handle
  82.  int amount = the number of lines to move the window.
  83.  
  84.  Moves the window indicated right on the screen, the screen is
  85.  updated to show the movement.  If there is insufficient space
  86.  to move the requested amount, the window is moved as far as
  87.  possible.
  88.  
  89. *****************************************************************/
  90.  
  91. void win_right(int handle, int amount)
  92. {
  93. extern struct screen_structure scr;
  94. extern struct window_structure w[];
  95.  int win_right;
  96.  
  97.  /* if the window selected is on top then save */
  98.  if(scr.active==handle)
  99.     win_save();
  100.  
  101.    /* calculate true right edge of window.
  102.       this depends on presence of frame */
  103.  
  104.    if(w[handle].frame==TRUE) win_right=w[handle].right+1;
  105.     else win_right=w[handle].right;
  106.  
  107.     /*return if already on right border */
  108.     if(win_right==scr.columns) return;  
  109.  
  110.     if(win_right+amount>=scr.columns)amount=scr.columns-win_right;
  111.  
  112.     /* change the window margin definitions to show the changes */
  113.     w[handle].right += amount;
  114.     w[handle].left+=amount;
  115.  
  116.  win_redraw_all();    /* show the changes */
  117.  
  118.  if(scr.active==handle){  /* if the window is active */
  119.    free(w[handle].buffer) ; /* free the buffer */
  120.    w[handle].buffer=NULL ;
  121.    update_margins();        /* update screen margins
  122.                                to reflect new active
  123.                                window area */
  124.     display_cursor();       /* update cursor position */
  125.  }
  126. }
  127.  
  128.  
  129. /*****************************************************************
  130.  
  131.  Usage: void win_left(int handle, int amount);
  132.  
  133.  int handle = window handle
  134.  int amount = the number of lines to move the window.
  135.  
  136.  Moves the window indicated left on the screen, the screen is
  137.  updated to show the movement.  If there is insufficient space
  138.  to move the requested amount, the window is moved as far as
  139.  possible.
  140.  
  141. *****************************************************************/
  142.  
  143. void win_left(int handle, int amount)
  144. {
  145. extern struct screen_structure scr;
  146. extern struct window_structure w[];
  147.  
  148.  int win_left;
  149.  
  150.  /* if the window selected is on top then save */
  151.  if(scr.active==handle)
  152.     win_save();
  153.  
  154.     /* calculate true left edge of window.
  155.        this depends on presence of frame */
  156.  
  157.     if(w[handle].frame==TRUE) win_left=w[handle].left-1;
  158.      else win_left=w[handle].left;
  159.  
  160.      if(win_left==0) return;  /*return if already on left border */
  161.  
  162.      if(win_left-amount<=0)amount=win_left-1;
  163.  
  164.     /* update the window margins to show the move */
  165.     w[handle].left  -= amount;
  166.     w[handle].right -= amount;
  167.  
  168.  win_redraw_all();   /* update the screen */
  169.  if(scr.active==handle){  /* if the window is active */
  170.    free(w[handle].buffer) ;
  171.    w[handle].buffer=NULL ;
  172.    update_margins();      /* update the screen margins
  173.                              to reflect changes made to
  174.                              the active window  */
  175.     display_cursor();     /* update cursor position */
  176.  }
  177. }
  178.  
  179.  
  180. /*****************************************************************
  181.  
  182.  Usage: void win_down(int handle, int amount);
  183.  
  184.  int handle = window handle
  185.  int amount = the number of lines to move the window.
  186.  
  187.  Moves the window indicated down on the screen, the screen is
  188.  updated to show the movement.  If there is insufficient space
  189.  to move the requested amount, the window is moved as far as
  190.  possible.
  191.  
  192. *****************************************************************/
  193.  
  194. void win_down(int handle, int amount)
  195. {
  196. int win_bottom;
  197.  
  198. extern struct screen_structure scr;
  199. extern struct window_structure w[];
  200.  
  201.  /* if the window selected is on top then save */
  202.  if(scr.active==handle)
  203.     win_save();
  204.  
  205.     /* calculate true top of window.
  206.        this depends on presence of frame */
  207.  
  208.     if(w[handle].frame==TRUE) win_bottom=w[handle].bottom+1;
  209.      else win_bottom=w[handle].bottom;
  210.  
  211.      if(win_bottom==scr.rows) return;  /*return if already on top*/
  212.  
  213.      if(win_bottom+amount>=scr.rows)amount=scr.rows-win_bottom;
  214.  
  215.     /* update the window margins to reflect change */
  216.     w[handle].top += amount;
  217.     w[handle].bottom +=amount;
  218.  
  219.  win_redraw_all(); /* update the screen */
  220.  if(scr.active==handle){  /* if the window is active */
  221.    free(w[handle].buffer) ; /* free the buffer */
  222.    w[handle].buffer=NULL ;
  223.    update_margins();        /* update the screen margins
  224.                                to reflect the new active
  225.                                window area */
  226.     display_cursor();     /* update cursor position */
  227.  }
  228. }
  229.  
  230.  
  231. /*****************************************************************
  232.  
  233.  Usage: void win_insert(int handle, int position);
  234.  
  235.  int handle = window handle
  236.  int position = relative position within the window stack.
  237.  
  238.  Places the window indicated by "handle" to the relative screen
  239.  location indicated.  Position 1 would be the first window on top
  240.  of the initial "desktop" window.  The screen is updated to show
  241.  the move.
  242.  
  243. *****************************************************************/
  244.  
  245. void win_insert(int handle, int position)
  246. {
  247. extern struct  screen_structure scr;
  248. extern struct window_structure w[];
  249.  
  250. int location,i;
  251.  
  252. if (handle==0) return;  /* can't move initial window */
  253.  
  254. if(position==scr.ptr) {  /* if it is moved to the top */
  255.   win_pop_top(handle);   /* pop it */
  256.   return;
  257. }
  258.  
  259. /* return if move to same location is requested. */
  260. if (handle==scr.list[position]) return; 
  261.  
  262.  location=win_validate(handle); /* see if window is open */
  263.  if (location==-1) return;        /* exit if not in list */
  264.  
  265. /* inserting a window requires that the window list be
  266.    rearranged.   The direction of the shift depends on whether the
  267.    window is moved up or down in the stack. */
  268.  
  269. win_save();  /* save top window before shuffle */
  270.  
  271.  /* shuffle order */
  272.  
  273.     /* if the position requested is higher in the stack than the */
  274.     /* actual location, do the following */
  275.  
  276.      if(position>location)    /* the window is moved up */
  277.        for(i=location;i<position;i++) scr.list[i]=scr.list[i+1];
  278.      else                     /* the window is moved down */
  279.        for(i=location;i>position;i--) scr.list[i]=scr.list[i-1];
  280.  
  281.  scr.list[position]=handle;
  282. win_redraw_all(); /* redraw the window */
  283. }
  284.